/*
 * Copyright (c) 2015 Travis Geiselbrecht
 *
 * Use of this source code is governed by a MIT-style
 * license that can be found in the LICENSE file or at
 * https://opensource.org/licenses/MIT
 */
#include <lk/err.h>
#include <lk/debug.h>
#include <lk/trace.h>
#include <stdio.h>
#include <string.h>
#include <lib/watchdog.h>
#include <platform.h>
#include <lk/compiler.h>
#include <lk/console_cmd.h>
#include <platform/debug.h>
#include <arch/ops.h>
#include <arch/arm/cm.h>
#include <target.h>


#define LOCAL_TRACE 1

static uint32_t count = 0;
/* routines called from lib/watchdog */
status_t platform_watchdog_init(lk_time_t  target_timeout,
                                lk_time_t *recommended_pet_period) {
    LTRACEF("target_timeout %u\n", (uint32_t)target_timeout);

    /* make sure the swdt is stopped */
    *recommended_pet_period = target_timeout > 1000 ? 1000: target_timeout;

    LTRACEF("recommended pet period %u\n", (uint32_t)*recommended_pet_period);

    /* set up the swdt */

    return NO_ERROR;
}

void platform_watchdog_set_enabled(bool enabled) {
    LTRACEF("enabled %u\n", enabled);
}

void platform_watchdog_pet(void) {
    //LTRACEF("pet\n");
    //target_set_wdi(true);
    //target_set_wdi(false);
    if(0 == (count ++) %2)
        target_set_debug_led(0, true);
    else
	target_set_debug_led(0, false);
}

